from django.db import models
from django.contrib import admin
from django.contrib.auth.admin import User

# Create your models here.
#
class AreasInfo(models.Model):
    name = models.CharField(max_length=50)
    parent_id = models.IntegerField(max_length=4)
    sort = models.IntegerField(max_length=4)
    def __unicode__(self):
        return self.name
    
    class Meta:
        ordering=['sort']
        
admin.site.register(AreasInfo)

#
class ScoreType(models.Model):
    data_type = models.IntegerField(max_length=2)
    name = models.CharField(max_length=50)
    sort = models.IntegerField(max_length=4)
    
    def __unicode__(self):
        return self.name
    class Meta:
        ordering=['sort']

admin.site.register(ScoreType)

class Node(models.Model):
    data_type= models.IntegerField(max_length=2)
    name = models.CharField(max_length=100)
    city = models.CharField(max_length=50)
    telphone = models.CharField(max_length=50)
    address = models.CharField(max_length=100)
    email = models.CharField(max_length=50)
    website = models.CharField(max_length=50)
    describe = models.TextField(max_length=500)
    
    create_date = models.datetime
    update_date = models.datetime
    
    def __unicode__(self):
        return self.name
    class Meta:
        ordering=['name']
        
class NodeAdmin(admin.ModelAdmin):
    list_filter = ('name','city')
    
admin.site.register(Node,NodeAdmin)

#
class Comments(models.Model):
    content = models.CharField(max_length=500)
    comment_date = models.datetime
    user = models.ForeignKey(User)
    review = models.ForeignKey(Review)
    def __unicode__(self):
        return self.content

class CommentsAdmin(admin.ModelAdmin):
    list_filter = ('title','content')
        
admin.site.register(Comments,CommentsAdmin)

class Review(models.Model):
    title = models.CharField(max_length=100)
    content = models.CharField(max_length=500)
    review_date = models.datetime
    user = models.ForeignKey(User)
    node = models.ForeignKey(Node)
    def __unicode__(self):
        return self.title

class ReviewAdmin(admin.ModelAdmin):
    list_filter = ('title','content')
        
admin.site.register(Review,ReviewAdmin)

